package com.example.chapter06ref;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

//public class ShareWriteActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
public class ShareWriteActivity extends AppCompatActivity implements  View.OnClickListener {

    private EditText et_name;
    private EditText et_age;
    private EditText et_height;
    private EditText et_weight;
    private CheckBox ck_married;
    private SharedPreferences preferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share_write);
        et_name = findViewById(R.id.et_name);
        et_age = findViewById(R.id.et_age);
        et_height = findViewById(R.id.et_height);
        et_weight = findViewById(R.id.et_weight);
        ck_married = findViewById(R.id.ck_married);

        findViewById(R.id.btn_save).setOnClickListener(this);
        preferences = getSharedPreferences("myconfig1127", Context.MODE_PRIVATE);
    }

    @Override
    public void onClick(View v) {
        String name = et_name.getText().toString();
        String age = et_age.getText().toString();
        String height = et_height.getText().toString();
        String weight = et_weight.getText().toString();

        SharedPreferences.Editor edit = preferences.edit();
        edit.putString("name", name);
        edit.putInt("age", Integer.parseInt(age));
        edit.putFloat("height", Float.parseFloat(height));
        edit.putFloat("weight", Float.parseFloat(weight));
        edit.putBoolean("married", ck_married.isChecked());
        edit.commit();

    }

//    @Override
//    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
//        String name = et_name.getText().toString();
//        String age = et_age.getText().toString();
//        String height = et_height.getText().toString();
//        String weight = et_weight.getText().toString();
//
//        SharedPreferences.Editor edit = preferences.edit();
//        edit.putString("name", name);
//        edit.putInt("age", Integer.parseInt(age));
//        edit.putFloat("height", Float.parseFloat(height));
//        edit.putFloat("weight", Float.parseFloat(weight));
//        edit.putBoolean("married", ck_married.isChecked());
//        edit.commit();


//    }
}